<?php

namespace  backend\components;


use common\services\Setting;
use yii;
use common\models\Logs;
use yii\base\Object;


class Utility extends Object{

  public static function recordLog()
  {
    $log_level = Setting::read('log_level');
    if($log_level == 2){
      self::_recordLog();
    }else if($log_level == 1){
      if(!in_array(\Yii::$app->controller->action->id,['index','recyclebin','view','desktop'])){
        self::_recordLog();
      }
    }else{

    }
  }
  private static function _recordLog(){
    //$arr = array_merge(\Yii::$app->request->post(),\Yii::$app->request->getQueryParams());
    $arr = \Yii::$app->request->post();

    $info = empty($arr)?'':var_export($arr,true);

    $uid = Yii::$app->user->getId()?Yii::$app->user->getId():0;
    $log = new Logs([
      'user_id' => $uid,
      'log_url' => 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'],
      'log_info' => $info,
      'log_ip' => Yii::$app->request->userIP,
    ]);
    $log->save();
  }




}
